'use strict'

module.exports = options => async (ctx, next) => {
  let { _limit, _page, _desc, _asc } = ctx.query
  _limit = _limit ? Math.floor(Number(_limit)) || 10 : 10
  _page = _page ? Math.floor(Math.floor(Number(_page))) || 1 : 1

  ctx.state.query = ctx.state.query || {}
  ctx.state.query._limit = _limit
  ctx.state.query._page = _page
  ctx.state.query._skip = (_page - 1) * _limit

  await next()
}
